package com.jing.product.controller;

import com.jing.common.core.domain.R;
import com.jing.common.core.web.controller.BaseController;
import com.jing.common.core.web.page.TableDataInfo;
import com.jing.product.domain.po.ProductAttributeCategory;
import com.jing.product.domain.vo.ProductAttrRelVO;
import com.jing.product.domain.vo.ProductAttributeCategoryVO;
import com.jing.product.domain.vo.ProductCategoryVO;
import com.jing.product.service.ProductAttributeCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @Author：HaoYunde
 * @Package：com.jing.product.controller
 * @Project：Jing
 * @name：ProductAttributeCategoryController
 * @Date：2024/5/24 11:17
 */
@RestController
@RequestMapping("productAttributeCategory")
@Validated
@Api(tags = "商品类型表")
public class ProductAttributeCategoryController extends BaseController {
    @Autowired
    private ProductAttributeCategoryService service;

    /**
     *查询商品属性类型表
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "查询商品属性类型表")
    public R page(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                  @RequestParam(required = false, defaultValue = "10") Integer pageSize){
        startPage();
        List<ProductAttributeCategoryVO> list =service.page();
        TableDataInfo dataTable = getDataTable(list);
        return R.ok(dataTable);
    }



    /**
     * 删除商品属性类型表
     * @param id
     * @return
     */
    @PostMapping("/delect")
    @ApiOperation(value = "删除商品属性类型表")
    public R delect(@Valid  @RequestParam Integer id){
        service.delect(id);
        return R.ok();
    }


    /**
     * 添加商品属性类型表
     * @param productAttributeCategory
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加商品属性类型表")
    public R add(@Valid @RequestBody ProductAttributeCategory productAttributeCategory){
        service.add(productAttributeCategory);
        return R.ok();
    }

    /**
     * 修改商品属性类型表
     * @param productAttributeCategory
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改商品属性类型表")
    public R update(@Valid @RequestBody ProductAttributeCategory productAttributeCategory){
        service.update(productAttributeCategory);
        return R.ok();
    }


    @GetMapping("/findAllproductAttributeCategoryName")
    @ApiOperation(value = "商品类型下拉框")
    public R findAllproductAttributeCategory(){
       List<ProductAttributeCategoryVO> list= service.findAllproductAttributeCategory();
       return R.ok(list);
    }


    /**
     * 查询属性规格
     * @param id
     * @param type
     * @return
     */
    @GetMapping("/getValueByid")
    @ApiOperation(value = "查询属性规格")
    public R getValueByid(@RequestParam Integer id,@RequestParam Integer type){
        List<ProductCategoryVO> list= service.getValueByid(id,type);
        return R.ok(list);
    }
    @GetMapping("/getValueByid2")
    @ApiOperation(value = "查询属性规格")
    public R getValueByid2(@RequestParam Integer id,@RequestParam Integer type){
        List<ProductCategoryVO> list= service.getValueByid2(id,type);
        return R.ok(list);
    }


    @PostMapping("saveProductAttributeCategory")
    @ApiOperation(value = "后台返回前台的值")
    public R<List<Map<Integer, String>>> saveProductAttributeCategory(@RequestBody List<ProductAttrRelVO> list){
        return R.ok(service.saveProductAttributeCategory(list));
    }


}
